package algorithms.roughgarden.part2.clustering;

import java.util.ArrayList;
import java.util.List;

import com.notion.algorithms.datastructures.UnionFindable;

public class Vertex implements UnionFindable{
	private final int value;
	private Vertex leaderVertex;
	private List<UnionFindable> subElements = new ArrayList<UnionFindable>();
	
	public Vertex(int value){
		super();
		this.value = value;
		this.leaderVertex = this;
		subElements.add(this);
	}	

	public int getValue() {
		return value;
	}


	public Vertex getLeaderVertex() {
		return leaderVertex;
	}

	public void setLeaderVertex(UnionFindable newLeaderVertex) {
		this.leaderVertex = (Vertex) newLeaderVertex;		
	}

	public int getSubtreeSize() {
		return subElements.size();
	}

	public List<UnionFindable> getSubelements() {
		return subElements;
	}
	@Override
	public boolean equals(Object obj) {
		Vertex v = (Vertex)obj;
		return v.getValue() == this.getValue();
	}
	
	@Override
	public String toString() {
		return Integer.toString(value);
	}

}
